February 10, 2020
In this page, we are going to see R commands. Try to install R and practice commands in the environment which will be more practical. Before we start it is time to remember below points.
Output for every command will be displayed in console. (Bottom Left)
rm(list=ls()) //First command to be executed as soon as we open the R Studio to clear R objects from RAM.
ls() //lists if any objects in RAM
setwd() //setting the working directory.
setwd(“C:/Users/Sridevi P/Desktop/Data Science/R Programs”)
list.files(“C:/Users/Sridevi P/Desktop/Data Science/R Advanced/“)
We saw few commands with preloaded Dataset mtcars. Now we are going to see about Loading external files into R.
TempObj1 = read.delim(“Filename.txt”, sep = “\t”, header = TRUE)
header = TRUE // If this is set to TRUE, then The first row will be treated as row names. We can also make it as FALSE if we dont want the first row to be treated as row names.
Actually the text file has below content.
TempObj3 = read.csv(“FileName.csv”, header = F)
For Example i have cars.csv file placed in my working directory, which i am loading to TempObj3 and then viewing it. Screenshots below
rownames=T // First row will be treated as row names as it is set to True.
Here we write CSV to a new output file, which will be saved in our working directory. Below screenshot explains the command and see output in console.
TempObj2 = read.xlsx(“Filename.xlsx”, sheetIndex = 1, header = TRUE)
liabrary(xlsx) is the command to load xlsx liabrary.
It is the same syntax as we have for csv output file write function The only difference is instead of csv, we put xlsx.
Not able to provide screenshot for reading and writing Excel Data as i am having issues with xls library function. Will fix this and update shortly. Meanwhile you can go through the commands and try to execute in RStudio.
Stay tuned for next set of commands!!!!